package com.lgx.common.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lgx.common.entity.CityDictonary;
import com.lgx.common.service.ICityDictonaryService;
import com.lgx.common.web.json.JsonUtils;

@Controller
@RequestMapping("/city/dict")
public class CityDictonaryController {

	private ICityDictonaryService cityDictonaryService;

	public ICityDictonaryService getCityDictonaryService() {
		return cityDictonaryService;
	}

	public void setCityDictonaryService(ICityDictonaryService cityDictonaryService) {
		this.cityDictonaryService = cityDictonaryService;
	}
	
	@RequestMapping("/list.do")
	public void list(HttpServletRequest request,HttpServletResponse response){
		String type = request.getParameter("type");
		String parentId = request.getParameter("parentId");
		
		List<CityDictonary> cds = this.cityDictonaryService.findCityDictonaryList(type, parentId);
		JsonUtils utils = new JsonUtils();
		String json;
		try {
			json = utils.converToJson(cds);
			response.setCharacterEncoding("utf-8");
			PrintWriter out = response.getWriter();
			out.print(json);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
